package git.bankview.wl.console;

import laya.semi.process.*;

import git.bankview.sl.schedule.ScheduleCommon;
import git.bankview.wl.common.*;

//import org.apache.log4j.Logger;

public class TaskMonitorActivity extends SqlQueryActivityBase
{
	//private static Logger log = Logger.getLogger(TaskMonitorActivity.class);
   
	protected StringBuffer buildSqlBuffer(IProcessContext oCtx)
		throws Exception
	{
		Object[] vStatus = (Object[])oCtx.getField("status");
		String oDateKey = (String)oCtx.getField("datekey");
		
		StringBuffer oSql = new StringBuffer("SELECT");
		oSql.append("  ts.datekey")		//c01
			.append(", ts.taskid")		//c02
			.append(", ts.execurl")		//c03
			.append(", ts.retrymax")	//c04
			.append(", ts.statuscode")	//c05
			.append(", ts.exectime")	//c06
			.append(", ts.termtime")	//c07
			.append(", ts.retrytimes")	//c08
			.append(", ts.errmsg")		//c09
			.append(", ts.taskdesc")	//c10
			.append(", ts.isignored")	//c11
			.append(" FROM taskschedule ts WHERE ");
			
		
		if (null == oDateKey || 0 == oDateKey.trim().length())
		{
			oSql.append("datekey = (select max(datekey) from taskschedule)");
		}
		else
		{
			oSql.append("datekey = ").append(ScheduleCommon.wrapDateSql(oDateKey));
		}
		
		if (null != vStatus && 0 < vStatus.length)
		{
			oSql.append(" and ts.statuscode in (");
			for (int i = 0; i < vStatus.length; ++i)
			{
				Integer status = (Integer)vStatus[i];
				if (0 < i)
					oSql.append(", ");
				
				oSql.append(status);
			}
			oSql.append(")");
		}
		
		return oSql;
	}
}
